<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>事件处理</title>
    <script src="../js/vue.js"></script>
    <style>

    </style>
</head>

<body>
    <div id="root">
        <h2>今天天气{{info}}</h2>
        <button @click="changeWeather">切换天气</button>
        <hr>
        <h3>a的值是：{{numbers.a}}</h3>
        <button @click="{{numbers.a++}}">带我让a增加</button>
        <h3>a的值是：{{numbers.b}}</h3>
        <button @click="{{numbers.b++}}">带我让a增加</button>
    </div>
    <script>
        Vue.config.productionTip = false

        const vm = new Vue({
            el: '#root',
            numbers: {
                a: 1,
                b: 1
            },
            data: {
                isHot: true
            },
            computed: {
                info() {
                    return this.isHot === true ? '炎热' : '凉爽'
                }
            },
            methods: {
                changeWeather() {
                    this.isHot = !this.isHot
                }
            },
            watch: {
                isHot: {
                    immediate: true,//c初始化时让handler调用一下
                    //当isHot被改时触发
                    handler(newValue, oldValue) {
                        console.log('isHot别修改了')
                    }
                },
                'number.a': {
                    handler() {
                        consol.log('a被改变了')
                    }
                },
                number: {
                    deep: true,//监视多级结构中属性的变化
                    handler() {
                        consol.log('numbers被改变了')
                    }
                },
            }
        })
        //第二种监视语法
        // vm.$watch('isHot', {
        //     immediate: true,//c初始化时让handler调用一下
        //     //当isHot被改时触发
        //     handler(newValue, oldValue) {
        //         console.log('isHot别修改了')
        //     }
        // })
    </script>
</body>

</html>